import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Pages from 'vite-plugin-pages'
import Layouts from 'vite-plugin-vue-layouts'
import vueSetupExtend from 'vite-plugin-vue-setup-extend'
import UnoCSS from 'unocss/vite'

export default defineConfig({
  base: './',
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/assets/styles/element/element.scss";`
      }
    }
  },
  plugins: [
    vue(),
    vueJsx(),
    vueSetupExtend(),
    Pages({
      dirs: 'src/views',
      exclude: ['**/components/**']
      // importMode: 'async',
    }),
    Layouts(),
    Components({
      resolvers: [ElementPlusResolver({ importStyle: 'sass' })]
    }),
    AutoImport({
      imports: ['vue', 'vue-router', 'pinia'],
      resolvers: [ElementPlusResolver({ importStyle: 'sass' })]
    }),
    UnoCSS()
  ],
  server: {
    port: 8080,
    host: '0.0.0.0',
    cors: true,
    proxy: {
      '/gaode_api': {
        target: 'https://restapi.amap.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/file_api/, '')
      }
    }
  }
})
